package com.bicon.botu.finance.payment.controller;

import com.bicon.botu.finance.payment.common.PaymentConstants;
import com.bicon.botu.finance.payment.service.AppPaymentInfoService;
import com.bicon.botu.finance.payment.service.RefundService;
import com.bicon.botu.finance.payment.service.TransferService;
import com.bicon.botu.finance.payment.entity.AppPaymentInfoEntity;
import com.bicon.botu.core.base.common.entity.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 宋旭
 * @Date: Created in 15:14 2017/7/18/018
 */

@RestController
@RequestMapping("/V1.0.0/transfer")
public class TransferController {

    @Autowired
    private AppPaymentInfoService appPaymentInfoService;

    @Autowired
    private TransferService transferService;

    @Autowired
    private RefundService refundService;

    @RequestMapping(value = "/transfer", method = RequestMethod.POST)
    public BaseResult transfer(@RequestParam(value = "code") String code, @RequestParam(value = "type") String type,
                               @RequestParam(value = "orderNum") String orderNum, @RequestParam(value = "payeeAccount") String payeeAccount,
                               @RequestParam(value = "amount") String amount,@RequestParam(value = "payeeName")  String payeeName,
                               @RequestParam(value = "identityCard") String identityCard, @RequestParam(value = "remark") String remark) {
        AppPaymentInfoEntity appPaymentInfoEntity = appPaymentInfoService.findOneByCode(code);
        if (null == appPaymentInfoEntity){
            return new BaseResult(PaymentConstants.RESPONSE_CODE_400, PaymentConstants.RESPONSE_MESSAGE_400, null);
        }
        if (30 > Double.valueOf(amount) || 200 < Double.valueOf(amount)) {
            return new BaseResult(PaymentConstants.RESPONSE_CODE_400, PaymentConstants.RESPONSE_MESSAGE_400, null);
        }
        return transferService.transfer(appPaymentInfoEntity,type,orderNum,payeeAccount,amount,payeeName,identityCard,remark);
    }


    @RequestMapping(value = "/refund", method = RequestMethod.POST)
    public BaseResult refund() {
        return refundService.refund();
    }

}
